package ae.pcfc.cldos.online.common.facade.provider;

import java.io.FileNotFoundException;

import org.springframework.transaction.annotation.Transactional;

import ae.pcfc.cldos.online.common.clddb.domain.manager.TempFileStorageDOM;
import ae.pcfc.cldos.online.common.facade.BaseFacade;
import ae.pcfc.cldos.online.common.facade.FileHandlerFacade;
import ae.pcfc.cldos.online.common.manager.FileStorageManager;
import ae.pcfc.cldos.online.common.vo.FileVO;



/**
 * File Handler Facade Implementation to handle file operations
 * @author ammar
 *
 */

public class FileHandlerFacadeImpl extends BaseFacade implements FileHandlerFacade {
	
	private TempFileStorageDOM tempFileStorageDOM;

	public void setTempFileStorageDOM(TempFileStorageDOM tempFileStorageDOM) {
		this.tempFileStorageDOM = tempFileStorageDOM;
	}
	
	private FileStorageManager fileStorageManager;
	
	public void setFileStorageManager(FileStorageManager fileStorageManager) {
		this.fileStorageManager = fileStorageManager;
	}
	
	@Transactional
	public FileVO getFileFromJavaStorageById(Long fileId) throws FileNotFoundException{
		return fileStorageManager.getFileFromJavaStorageById(fileId);
	}


	@Transactional
	public void updateTransferFlag(FileVO fileVO) {
		tempFileStorageDOM.markTransferedById(fileVO.getId());
		
	}

	@Transactional
	public void deleteTransferedFiles() {
		tempFileStorageDOM.deleteTransferedFiles();
	}
	
	@Transactional
	public FileVO getFileFromGSStorageById(Long fileId) throws FileNotFoundException{
		return fileStorageManager.getFileFromGSStorageById(fileId);
	}
}
